Skip to content

fix(weibo): decouple NoWM evaluation state from CacheStandardVersion - #254

Merged
chialecode merged 2 commits into
mainfrom
fix/252-weibo-nowm-quality-decouple
Nov 30, 2026
Merged

chialecode merged 2 commits into
mainfrom
fix/252-weibo-nowm-quality-decouple

Conversation

@chialecode

Copy link
Copy Markdown
Owner

Closes #252

做了什么

将微博无水印伴侣图(/oslarge/、images/NN_nowm.<ext>)的评估状态与 CacheStandardVersion 解耦(对应 FR-CACHE-006、FR-CACHE-010、DEC-078、DEC-079、DEC-096,保持 item.json v1、library.db v2、cache-queue.json v3 零结构版本升级),彻底消除关闭「微博同时保存无水印版(WeiboRemoveWatermark == false)」时跳过静图/混排帖画质与历史补全的缺陷:

  1. 独立状态字段与向后兼容(internal/library/schema.go、internal/library/merge.go):
    • 新增 ItemMetadata.WeiboNoWMState(json:"weiboNoWMState,omitempty")及常量 WeiboNoWMStatePending = "pending"、WeiboNoWMStateChecked = "checked",新增辅助函数 WeiboHasStaticImageSlots 与 WeiboNoWMAlreadyEvaluated。
    • SanitizeItemMetadata / PortableManifest 仅允许微博站点保留 "" / "pending" / "checked",非微博站点与非法值统一清洗置空;MergeItemMetadata 按 "checked" > "pending" > "" 合并。
    • 更新 WeiboNeedsNoWMBackfill(meta, removeWatermark):"checked" 返回 false;"pending" 在 removeWatermark == true 下检查 len(WeiboStaticImageSlotsMissingNoWM(meta)) > 0;旧版 WeiboNoWMState == "" 继续沿用 CacheStandardVersion < WeiboNoWMStandardVersion (3) 规则,保证既往 v3–v6 404 /oslarge/ 条目零重复请求。
  2. 移除 removeWM == false 整体跳过并补全状态流转(internal/download/weibo_plan.go、internal/download/weibo_backfill.go、internal/service/backfill.go、internal/service/cache_conflicts.go):
    • 移除 weiboNeedsQualityBackfill 与 weiboNeedsHistoricalOtherBackfill 中 !removeWM && len(WeiboStaticImageSlotsMissingNoWM(meta)) > 0 的提前跳过,更新 weiboCanStampV4Tier0 在 removeWM == false 下不再阻断 v6 打标。
    • 在 executeWeiboPostTask(applyWeiboPostStandardAndNoWMState)、BackfillWeiboNoWMCompanions、Tier A 离线链接升级与 Tier 0 元数据回写(stampWeiboStandardAndNoWMState)中统一维护 WeiboNoWMState:关闭无水印完成缓存/升级/核验且存在未评估静图槽位时写 v6 + "pending" 立即收敛(已评估过的旧 v3–v6 静图槽位保留 "checked");开启无水印并评估全部静图槽位后置 "checked"(BackfillWeiboNoWMCompanions / Bucket B 快速 CDN 处理 v6 + "pending" 条目时正常下载 NN_nowm 或收敛 404,保留 v6 不降级)。
  3. 同步设计文档与合成回归测试:
    • 更新 docs/design/data-and-cache.md、docs/design/subscriptions.md。
    • 补充 TestWeiboNoWMStateSanitizeMergeAndPortableRoundTrip、TestWeiboCacheStandardVersionAndOfflineHelpers 解耦分支、TestWeiboNoWMStateDecoupledStampingAndV6PendingFastCDNBackfill、TestWeiboNoWMDecoupledRemoveWMFalseQualityBackfillThenToggleTrueFastCDN,并同步强化 TestDEC096WeiboBackfillTierC2BackoffClearOrderAndRemoveWatermarkFalseNoLoop。

验证

  • go run ./tools/check(退出码 0,总耗时 12m17.842s,基于提交 fc36527):
    • gofmt -l: OK (385ms)
    • go vet ./...: OK (9.467s)
    • go test ./...: OK (11m37.715s,全部包非缓存完整执行通过,含 internal/library 35.436s、internal/download 164.426s、internal/service 151.163s)
    • dependency direction: OK (2.821s)
    • trace-server linux build: OK (25.297s)
    • tools/checkdocs: OK (2.034s,未找到本地参考索引,公开内容与链接校验通过)
    • git diff --check HEAD: OK (123ms)
  • 定向回归测试(退出码 0,-count=1):
    • go test -count=1 -v -run "TestWeiboNoWMState|TestWeiboCacheStandardVersionAndOfflineHelpers|TestBackfillWeiboNoWMCompanions|TestDEC096WeiboBackfillTierC2BackoffClearOrderAndRemoveWatermarkFalseNoLoop|TestWeiboNoWMDecoupledRemoveWMFalseQualityBackfillThenToggleTrueFastCDN|TestWeiboTierC2AbbreviatedPostAndWatermarkOffNeverFetchesOSLargeOrStampsV5|TestWeiboOptionalNoWMCompanion418DoesNotTripBackoffOrFailPrimary" ./internal/library ./internal/download ./internal/service(全部 PASS)
  • GitHub Actions CI repository-quality(建 PR 后自动执行)
  • not-run:真实站点请求(本次仅使用合成夹具验证,0 次真实请求至微博);tools/uishots / tools/package -install(未改动界面、打包或安装路径)。
  • 推送说明:本分支在 git worktree 中开发,已先完整通过 go run ./tools/check;按 LESSONS.md 推送时使用 git push --no-verify 以规避 pre-push 钩子注入 GIT_DIR 导致 tools/release 测试污染 worktree 引用的已知问题。

风险

风险等级:低风险

  • 未触及高风险清单(未改动 tools/package、tools/release、internal/credential、internal/sitecheck、tools/actcheck、.github/;未修改任何持久化数据文件结构版本,保持 item.json v1、library.db v2、cache-queue.json v3;未删除或弱化既有测试)。
  • 旧版无 weiboNoWMState 字段的 v3–v6 静图清单保持完全向后兼容,不会触发 404 /oslarge/ 重复抓取。

每个提交都带 Signed-off-by(git commit -s)。

Decouple Weibo /oslarge/ watermark-free companion evaluation from
CacheStandardVersion via optional item.json field weiboNoWMState
("" | "pending" | "checked", zero schema version bumps) so disabling
WeiboRemoveWatermark never skips quality or historical backfill on
static-image/mixed posts.

- internal/library: add ItemMetadata.WeiboNoWMState, constants
  WeiboNoWMStatePending/WeiboNoWMStateChecked, sanitization (Weibo-only
  allowlist), merge precedence (checked > pending > ""), portable
  manifest round-trip, and decoupled WeiboNeedsNoWMBackfill with full
  legacy v3-v6 404 compatibility.
- internal/download & internal/service: remove removeWM==false skips
  in weiboNeedsQualityBackfill, weiboNeedsHistoricalOtherBackfill, and
  weiboCanStampV4Tier0; stamp v6 + "pending" when removeWM==false and
  transition "pending" -> "checked" in BackfillWeiboNoWMCompanions
  (preserving v6 on Fast CDN Bucket B) and executeWeiboPostTask.
- docs/design: document weiboNoWMState in data-and-cache.md and
  subscriptions.md.
- tests: add unit and E2E regression tests covering removeWM=false
  upgrade convergence, subsequent removeWM=true Fast CDN Bucket B
  catch-up (200 OK and 404), and legacy v3-v6 404 non-refetch.

Verification: go run ./tools/check passed (12m17.842s); real-site
requests not-run (synthetic fixtures only).

Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
@chialecode

Copy link
Copy Markdown
Owner Author

Agent:独立干净上下文审查(pr-reviewer-3,审阅提交 fc3652719da754922f11a775e7a19ad8eb4b835a,关联 #252)

审查结论

需要修改(先修复)

核心方案(以可选 ItemMetadata.WeiboNoWMState "" / "pending" / "checked" 将微博 /oslarge/ 伴侣图评估状态与 CacheStandardVersion 解耦、零数据结构版本升级、兼容旧版 v3–v6 404 不重抓、取消 removeWM == false 下的画质/历史跳过并在开启 removeWM == true 后经 Bucket B 快速 CDN 收敛)整体清晰、风险分级准确(低风险,零高风险路径、纯 LF、DCO 通过、无公开内容泄漏、无测试弱化)。审查中发现 2 处可复现的 P2 边界状态缺陷,建议在本 PR 内修复并复审:

阻塞问题

  1. [P2] internal/download/weibo_plan.go:2872-2878(applyWeiboPostStandardAndNoWMState):removeWM == false 下静图主图下载失败产生 partial 条目时误标 WeiboNoWMState = "checked"

    • 触发条件:WeiboRemoveWatermark == false(ranNoWM == false)缓存含静图的新微博时,所有静图主图均发生非停机错误(如 HTTP 503/超时)导致落盘 pg.Image == ""(或部分静图失败而其余已成功槽位已有 NoWatermark);此时 meta.Status == "partial"、len(meta.Missing) > 0、hasStatic == true(来自 weiboPlanHasStaticImagePages(plan)),而 library.WeiboStaticImageSlotsMissingNoWM(*meta) 因跳过 imgPath == "" 返回空切片(len(missingSlots) == 0)。
    • 实际结果:第 2875 行 if ranNoWM || len(missingSlots) == 0 在零张静图落盘、从未请求 /oslarge/ 且条目为 partial 的情况下写入 meta.WeiboNoWMState = "checked"。
    • 影响:局部状态语义失真;一旦该本地 partial 存根与另一节点在 removeWM == false 下完整缓存的同条目(WeiboNoWMState == "pending")执行 MergeItemMetadata,"checked"(rank 2)会覆盖 "pending"(rank 1),导致合并后的完整条目永久跳过 /oslarge/ 补全。
    • 修复标准:applyWeiboPostStandardAndNoWMState 中,当 !ranNoWM 且 len(missingSlots) == 0 时,仅在 meta.Status == "complete" && len(meta.Missing) == 0 && library.WeiboHasStaticImageSlots(*meta) 时才写 WeiboNoWMStateChecked;当 meta.Status != "complete" || len(meta.Missing) > 0 且 !library.WeiboHasStaticImageSlots(*meta) 时保持 WeiboNoWMState = ""(ranNoWM == true 且零静图落盘的 partial 存根同理不标 "checked")。补充覆盖 removeWM == false 静图主图失败生成 partial 条目不断言为 "checked" 的单测。
  2. [P2] internal/service/cache_conflicts.go:2271-2312(weiboCanStampV4Tier0 与 stampWeiboStandardAndNoWMState):纯离线 Tier 0 / Tier A 路径未守卫 SkipAutoRecheck 且以 removeWM || alreadyEval 虚标 "checked"

    • 触发条件:weiboCanStampV4Tier0 未检查 meta.SkipAutoRecheck;若一条 < v3 未评估无水印的静图条目在 fresh, ok := b.lib.GetItem(...) 重读时已被并发置为 SkipAutoRecheck == true(或在 removeWM == true 下直接调用 stampWeiboStandardAndNoWMState 处理 !alreadyEval && missingNoWM 条目),library.WeiboNeedsNoWMBackfill(fresh, true) 会因 SkipAutoRecheck 返回 false,导致 weiboCanStampV4Tier0 返回 true,随后 stampWeiboStandardAndNoWMState 第 2303 行 if removeWM || alreadyEval 将从未访问 /oslarge/ 的条目写成 v6 + WeiboNoWMState = "checked"。
    • 实际结果:纯离线元数据回写路径绕过 SkipAutoRecheck 修改了条目版本,并在 0 次 CDN 请求下伪造 "checked" 状态(后续若手动恢复或版本化解除 SkipAutoRecheck,该条目将永久无法触发 /oslarge/ 补全)。
    • 修复标准:① weiboCanStampV4Tier0 首行增加 meta.SkipAutoRecheck 检查直接返回 false;② stampWeiboStandardAndNoWMState 仅在 alreadyEval 为真时对 missingNoWM 写 WeiboNoWMStateChecked、否则写 WeiboNoWMStatePending(移除 removeWM || 与多余的 removeWM 参数),保证纯离线打标永不凭开关值虚标 "checked";补对应边界单测。

非阻塞建议(至多 3 条)

  1. [建议] internal/library/merge.go:515(MergeItemMetadata):当前仅按 weiboNoWMStateRank(checked > pending > "")比较,若 local 为旧版已评估 v5 + ""(WeiboNoWMAlreadyEvaluated(local) == true)而 imported 为 v6 + "pending",合并结果会回退为 "pending"(开启 removeWM 时多做一次无害的 /oslarge/ 404 探测后收敛为 "checked")。如需在跨节点合并场景下同样保持旧版 v3–v6 零重复请求,可结合 WeiboNoWMAlreadyEvaluated(针对含静图槽位的旧版 v3+ 清单)视作已评估。

已审查范围与未覆盖项

  • 已审查范围:PR fix(weibo): decouple NoWM evaluation state from CacheStandardVersion #254 全部 13 个改动文件及其完整上下文调用链(internal/library/schema.go、merge.go、internal/download/weibo_backfill.go、weibo_plan.go、replace.go、internal/service/backfill.go、cache_conflicts.go、weibo_planner.go、docs/design/data-and-cache.md、subscriptions.md 及新增/更新单测);核验了 item.json v1 / library.db v2 / cache-queue.json v3 零结构版本变更、零高风险路径、纯 LF 换行符、DCO 签名、公开内容脱敏与反循环收敛路径。
  • CI 状态(审阅时点):DCO、CodeQL、Analyze (actions)、Analyze (go) 均已通过;repository-quality 正在运行 Run race detector tests(pending)。
  • not-run:审查者未在本地重跑 go run ./tools/check(复审修复提交时以新头提交的完整 repository-quality CI 通过为准),未执行真实微博站点请求。

Address PR #254 review findings:
- In applyWeiboPostStandardAndNoWMState, require saved local static images
  (library.WeiboHasStaticImageSlots) and all non-dead planned static pages
  saved before stamping WeiboNoWMState="checked", preventing 0-image or
  transient partial stubs from overriding "pending" during multi-node merges.
- Guard weiboCanStampV4Tier0 with meta.SkipAutoRecheck and remove removeWM
  from stampWeiboStandardAndNoWMState so pure offline Tier 0 / Tier A paths
  never fabricate "checked" when /oslarge/ was not evaluated.
- Preserve evaluated legacy v3-v6 static-image items as "checked" when
  MergeItemMetadata merges them with a v6+"pending" peer.
- Add synthetic unit tests covering all three behaviors.

Signed-off-by: chialecode <315431287+chialecode@users.noreply.github.com>
@chialecode

Copy link
Copy Markdown
Owner Author

Agent:已修复全部 2 项 P2 与 1 项非阻塞建议(提交 2bbe1d6b5b7a82978deaa43b22d1a4b633bc8317,--no-verify 推送,详见 LESSONS.md worktree pre-push hook 已知问题):

  1. P2 feat(m1): implement native media workflows with recoverable state #1 (internal/download/weibo_plan.go):applyWeiboPostStandardAndNoWMState 改为基于本地已落盘静态图(library.WeiboHasStaticImageSlots)与 isComplete || weiboAllNonDeadPlannedStaticPagesSaved(plan, *meta) 判断,0 图残缺桩及存在瞬时失败静图页的 partial 条目不再伪造 WeiboNoWMState = "checked"(仅永久失效占位 GIF 缺失时允许标记 checked),同时清理已无引用的 weiboPlanHasStaticImagePages。
  2. P2 feat(m2): versions, dev auto-install, signed release updates and weekly release #2 (internal/service/cache_conflicts.go, internal/service/backfill.go):weiboCanStampV4Tier0 增加 meta.SkipAutoRecheck 早退守卫;stampWeiboStandardAndNoWMState 移除 removeWM 参数与 removeWM || 短路,离线 Tier 0 / Tier A 路径仅在 WeiboNoWMAlreadyEvaluated 为真时标记 "checked",否则一律写入 "pending"。
  3. 非阻塞建议 (internal/library/merge.go):MergeItemMetadata(MergeKeepLocal / MergeUnion)中若任一侧为旧版 v3–v6 + "" 已评估静图条目,合并结果保持 "checked",避免与 v6 + "pending" 合并时倒退为 "pending"。
  4. 新增回归测试:
    • internal/download/weibo_media_quality_test.go:TestWeiboNoWMPartialStubsNeverFabricateCheckedState(覆盖 0 图残缺桩、双图瞬时 503 局部失败、ranNoWM 瞬时失败与永久占位 GIF 失效 4 种场景)
    • internal/service/weibo_media_quality_backfill_test.go:TestWeiboTier0SkipAutoRecheckAndOfflineStampNeverFabricatesChecked
    • internal/library/manifest_conflict_fields_test.go:扩展 TestWeiboNoWMStateSanitizeMergeAndPortableRoundTrip 覆盖旧版 v5 + "" 与 v6 + "pending" 双向合并及残缺桩合并

验证证据(2bbe1d6)

  • go test -count=1 -v ./internal/library -run 'TestWeiboNoWMStateSanitizeMergeAndPortableRoundTrip|TestWeiboCacheStandardVersionAndOfflineHelpers':PASS
  • go test -count=1 -v ./internal/download -run 'TestWeiboNoWM|TestWeiboV6':PASS
  • go test -count=1 -v ./internal/service -run 'TestWeiboNoWM|TestWeiboTier0|TestDEC096WeiboBackfill':PASS
  • go run ./tools/check:ALL CHECKS PASSED(gofmt -l、go vet ./...、全量 go test ./...、依赖方向、trace-server Linux 交叉编译、tools/checkdocs、git diff --check HEAD)
  • 纯 LF 检查:7/7 修改文件无 CR 字节
  • git merge-tree --write-tree origin/main HEAD:零冲突

@chialecode

Copy link
Copy Markdown
Owner Author

Agent:复审结论(pr-reviewer-3,审阅修复提交 2bbe1d6b5b7a82978deaa43b22d1a4b633bc8317,增量对比 fc36527..2bbe1d6,关联 #252)

审查结论

可合并(技术审查通过;合并前仍须等待当前头提交 2bbe1d6 的必需检查 repository-quality CI 全部通过)

阻塞项复核结果

  1. [P2 已修复] internal/download/weibo_plan.go(applyWeiboPostStandardAndNoWMState + weiboAllNonDeadPlannedStaticPagesSaved):已改为以 library.WeiboHasStaticImageSlots(*meta) 为前提,并在 ranNoWM、len(missingSlots) == 0 及 canCarryPrevNoWM 分支统一要求 isComplete || weiboAllNonDeadPlannedStaticPagesSaved(plan, *meta),零图/瞬时 503 残缺桩不再误标 "checked",同时保留对永久失效占位图 partial 条目收敛为 "checked" 的防循环行为,并移除未使用的 weiboPlanHasStaticImagePages。已由 TestWeiboNoWMPartialStubsNeverFabricateCheckedState(4 个子场景含多端合并)验证。
  2. [P2 已修复] internal/service/cache_conflicts.go & internal/service/backfill.go(weiboCanStampV4Tier0 + stampWeiboStandardAndNoWMState):weiboCanStampV4Tier0 首行已增加 meta.SkipAutoRecheck 守卫;stampWeiboStandardAndNoWMState 已移除 removeWM 参数,纯离线 Tier 0 / Tier A 路径仅在既有 WeiboNoWMAlreadyEvaluated 为真时写 "checked"、否则写 "pending"。已由 TestWeiboTier0SkipAutoRecheckAndOfflineStampNeverFabricatesChecked(5 个子场景)验证。
  3. [非阻塞建议已采纳] internal/library/merge.go(MergeItemMetadata):已结合 WeiboHasStaticImageSlots && WeiboNoWMAlreadyEvaluated 在双方向合并中保留旧版 v3–v6 已评估静图条目为 "checked",同时保持 v2 + "" 与零图残缺桩与 v6 + "pending" 合并结果为 "pending";已补充 TestWeiboNoWMStateSanitizeMergeAndPortableRoundTrip 2b 用例。

合规与门禁核验(提交 2bbe1d6b5b7a82978deaa43b22d1a4b633bc8317)

  • 风险分级:低风险(零高风险路径,零持久化结构版本变更,item.json v1 / library.db v2 / cache-queue.json v3)。
  • 工程卫生:7/7 新增改动文件(及全 PR 13/13 文件)均为纯 LF;全部提交含 DCO Signed-off-by;无公开内容泄漏;无测试弱化;与 origin/main 可干净合并(MERGEABLE)。
  • CI 状态(复审时点):DCO、Analyze (actions) 通过;repository-quality(Run quality gates 进行中)与 Analyze (go) 为 pending。
  • not-run:审查者未在本地重跑 go run ./tools/check(以作者实跑记录及 GitHub Actions repository-quality 绿灯为准),未执行真实微博站点请求。

@chialecode
chialecode merged commit 8bf9892 into main Nov 30, 2026
5 of 7 checks passed
@chialecode
chialecode deleted the fix/252-weibo-nowm-quality-decouple branch November 30, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(weibo): decouple NoWM state from CacheStandardVersion so removeWM=false never skips quality backfill

1 participant